<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>质量管理</title>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script src="../../../../static/struct/layuimini/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="UTF-8"></script>
    <link rel="stylesheet" href="../../../../static/struct/layuimini/lib/layui-v2.5.5/css/layui.css " media="all">
    <link rel="stylesheet" href="../../../../static/struct/layuimini/css/public.css" media="all">
    <script src="../../../../static/struct/layuimini/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
    <script src="../../../../static/js/generaljs/watermarkbycanvas.js" charset="UTF-8"></script>
    <script src="../../../../static/js/lims/ReportReSignJs.js" charset="utf-8"></script>

</head>

<body onload="addWaterMarker()" style="margin: 10px 10px 10px 10px">

    <blockquote class="layui-elem-quote layui-quote-nm">
        <div class="layui-form-item">
            Lims 质量管理
        </div>
    </blockquote>
        <div class="layui-form-item">
            <div class="layui-inline">
                    <button type="button" class="layui-btn "  id="rejectSendBtnId">不符合项转发</button>
                    <button type="button" class="layui-btn "  id="rejectCancelBtnId">转发撤消</button>

                    <button type="button" class="layui-btn "  id="viewProcessResultBtnId">查看处理结果</button>
                    <button type="button" class="layui-btn "  id="billRejectBtnId">处理结果退回</button>
                    <button type="button" class="layui-btn "  id="rejectBtnId">结项确认</button>
            </div>
        </div>
    <table class="layui-hide" id="qualityManageId" lay-filter="qualityManageFilter"></table>





    <script>
        layui.use(['form', 'table','layer'], function(){
            let $ = layui.jquery,
                table = layui.table,
                layer = layui.layer;
            //显示被驳回的委托/任务表格
            table.render({
                elem : '#qualityManageId'
                ,url : '/loading/rejectBills'
                ,cols : [
                    [
                        {checkbox : true , fixed : true , id : 'checkboxId'}
                        ,{field   : 'pkRejectInfo' , title : '主键' , width : '50' , sort : true , fixed : true , hide : true }
                        ,{field   : 'rejectOrder' , title : 'No.' , width : '80' , sort : true , fixed : true }
                        ,{field   : 'taskId' , title : '单据号' , width : '200' , sort : true , fixed : true }
                        ,{field   : 'rejectInfo' , title : '驳回信息' , width : '300' , sort : true , fixed : true }
                        ,{field   : 'def1' , title : '驳回日期' , width : '200' , sort : true , fixed : true }
                        ,{field   : 'def2' , title : '驳回人' , width : '100' , sort : true , fixed : true , hide : true}
                        ,{field   : 'def3' , title : '处理状态' , width : '120' , sort : true , fixed : true }
                        ,{field   : 'def4' , title : '处理人' , width : '150' , sort : true , fixed : true }
                        ,{field   : 'def5' , title : '结项时间' , width : '200' , sort : true , fixed : true , hide : true }
                    ]
                ]
                ,id : 'tableReload'
                ,page : true
                ,height: 'full-200'
                ,limit: 10
                ,limits: [10, 20, 30, 40, 50]
            });


            //var checkStatus = table.checkStatus('qualityManageFilter'),data = checkStatus.data;

            //处理结果退回
            $("#billRejectBtnId").click(function () {
                var selectData = layui.table.checkStatus('tableReload').data;
                if(selectData.length > 1){
                    layer.alert("为保证质量管理的流畅和完整性，请不要同时操作两条或以上的数据");
                    return;
                }
                if(selectData.length < 1){
                    layer.alert("请选择一条记录进行操作");
                    return;
                }
                layer.prompt({
                    formType: 2,
                    title: '请录入驳回原因并邮件发回给处理人',
                    closeBtn : false,
                    area: ['500px', '300px'],
                    id : 'rejectDialogId',
                    scrollbar : false,
                    anim: 2
                },function (value, index, elem) {
                    var loading = layer.load(1);
                    var data = {};
                    var rejectedResult = value.replace(/^\s*|\s*$/g,"");
                    //console.log(selectData[0].taskId);
                    var taskid = selectData[0].pkRejectInfo;
                    data['rejectedResult'] = rejectedResult;
                    data['taskIdCode'] = taskid;
                    $.ajax({
                        url: "/LimsWebControllers/rejectProcessToProcessor",
                        type: 'post',
                        data: JSON.stringify(data),
                        contentType: "application/json;charset=utf-8",
                        success: function(result) {
                            console.log(result)
                            //var json = eval(result);
                            if (result.code == '200'){
                                layer.close(loading);
                                parent.layer.msg('委托/任务单' + taskid  + '退回成功！');
                            }else {
                                layer.close(loading);
                                parent.layer.alert('驳回失败，原因：' + result.msg);
                            }
                        }
                    });
                    layer.close(index);
                });
            });



            $("#rejectSendBtnId").click(function(){
                var selectData = layui.table.checkStatus('tableReload').data;
                if(selectData.length > 1){
                    layer.alert("为保证质量管理的流畅和完整性，请不要同时操作两条或以上的数据");
                    return;
                }
                if(selectData.length < 1){
                    layer.alert("请选择一条记录进行操作");
                    return;
                }
                //console.log(selectData[0].pkRejectInfo);
                parent.layer.open({
                    title : '请选择处理人员',
                    type: 2,
                    area: ['500px', '450px'],
                    btn : ['确定分配','取消'],
                    yes : function(index,layero){
                        console.log(index);
                        var transferValue = $(layero).find("iframe").contents().find("#human").text();//获取子页面元素
                        var uurl = $(layero).find("iframe").contents().find("#human");
                        var transferArr = transferValue.split('已选处理人');
                        if (transferArr[1] == '无数据' || transferArr.length < 1){
                            parent.layer.alert('请至少选择一名处理人');
                            return;
                        }
                        console.log(transferArr[1]);

                        var url = window.location.href ;
                        console.log(uurl);
                        console.log(window.location.search);
                        var urlArr = url.split('taskid=');
                        //组装json
                        var param = {};
                        param['pk'] = selectData[0].pkRejectInfo;
                        param['users'] = transferArr[1].substring(0,transferArr[1].length-1);
                        //开始回写
                        let loading = parent.layer.load(1);
                        $.ajax({
                            type:"post",
                            url:"/LimsWebControllers/sendRejectBillToUserController",
                            data:JSON.stringify(param),
                            contentType:"application/json;charset=utf-8",
                            dataType:"json",
                            success:function(res){
                                if (res.code == '200'){
                                    parent.layer.close(loading);
                                    parent.layer.closeAll();
                                    parent.layer.msg('操作成功');
                                }else{
                                    parent.layer.close(loading);
                                    parent.layer.closeAll();
                                    parent.layer.alert(res.msg);
                                }
                            }
                        });
                    },
                    content: ['lims/sendRejectToHuman?taskid=' + selectData[0].taskId,'no'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                });
            });


            /**
             * 转发撤消点击事件
             */
            $("#rejectCancelBtnId").click(function(){
                var selectData = layui.table.checkStatus('tableReload').data;
                if(selectData.length < 1){
                    layer.alert("请至少选择一条记录进行撤消");
                    return;
                }
                //var param = {};
                //param['pk'] = selectData;
                //console.log(selectData);
                let loading = parent.layer.load(1);
                $.ajax({
                    type:"post",
                    url:"/LimsWebControllers/RejectCancelController",
                    data:JSON.stringify(selectData),
                    contentType:"application/json;charset=utf-8",
                    dataType:"json",
                    success:function(res){
                        if (res.code == '200'){
                            parent.layer.close(loading);
                            parent.layer.msg(res.msg);
                        }else{
                            parent.layer.close(loading);
                            parent.layer.alert(res.msg);
                        }
                    }
                });
            });


            /**
             * 结项确认点击事件
             */
            $("#rejectBtnId").click(function(){
                var selectData = layui.table.checkStatus('tableReload').data;
                if(selectData.length < 1){
                    layer.alert("请至少选择一条记录进行确认");
                    return;
                }
                let loading = parent.layer.load(1);
                $.ajax({
                    type:"post",
                    url:"/LimsWebControllers/RejectConfirmController",
                    data:JSON.stringify(selectData),
                    contentType:"application/json;charset=utf-8",
                    dataType:"json",
                    success:function(res){
                        if (res.code == '200'){
                            parent.layer.close(loading);
                            parent.layer.msg(res.msg);
                        }else{
                            parent.layer.close(loading);
                            parent.layer.alert(res.msg);
                        }
                    }
                });
            });



        });
    </script>

</body>
</html>